<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="webjars/layui/2.3.0/css/layui.css">
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">车牌号码</label>
        <div class="layui-input-block">
            <input type="text" name="carnum" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <button type="button" class="layui-btn" id="test1">
        <i class="layui-icon">&#xe67c;</i>上传图片
    </button>

    <div class="layui-form-item">
        <label class="layui-form-label">是否私有</label>
        <div class="layui-input-block">
            <input type="radio" name="isprivate" value="0" title="私有">
            <input type="radio" name="isprivate" value="1" title="非私有" checked>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="webjars/layui/2.3.0/layui.js"></script>
<script>
    //Demo
    layui.use(['form','jquery','upload'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#test1' //绑定元素
            ,url: '/upload' //上传接口
            ,done: function(res){
                //上传完毕回调
            }
            ,error: function(){
                //请求异常回调
            }
        });
        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            $.ajax({
                url:'carport',
                data:JSON.stringify(data.field),
                method:'post',
                dataType:'json',
                contentType: 'application/json;charset=utf8',
                success: function(){
                    layer.msg('执行成功');
                }
            })
            return false;
        });
    });
</script>

</body>
</html>